from sqlalchemy import Column,Integer,String,CHAR,FLOAT
from sqlalchemy.dialects.mysql import LONGTEXT
from datetime import datetime
from models.base import Base


class orders_info(Base):
    __tablename__ = 'order_info'
    id = Column(Integer,primary_key=True, autoincrement=True)
    order_number = Column(String(30), nullable=False)
    title = Column(String(100), nullable=False)
    author = Column(String(20), default='佚名')
    chars_sum = Column(Integer, default=0)
    create_time = Column('create_time', Integer)
    similar_rate = Column(FLOAT, default=0)
    status = Column(CHAR, default='0')
    taobao_orders = Column(String(30), nullable=False)
    completed = Column(Integer,default=0)
    file_path = Column(String(250), default='')


    def __init__(self):
        self.create_time = int(datetime.now().timestamp())

    @property
    def create_datetime(self):
        if self.create_time:
            return datetime.utcfromtimestamp(self.create_time+28800).strftime("%Y-%m-%d %H:%M:%S")
        else:
            return None